using System;

namespace Scenario.Modules.DM.DataModel
{
	public class XMLDocumentAttachFiles : bOSdotNET.XML.Data.XMLObjectSet 
	{
		public const string MAIN_NODE	= "Attaches";

		public XMLDocumentAttachFiles()
		{
			this.Init();
		}

		public XMLDocumentAttachFiles(System.Xml.XmlNode nodeList)
		{
			this.Parse (nodeList);
		}

		public override void Init()
		{
			this.RemoveAll();
		}

		public override void Parse(System.Xml.XmlNode nodeList)
		{
			this.Init();

			System.Xml.XmlNode node;

			for ( int i=0; i<nodeList.ChildNodes.Count;i++)
			{
				node = nodeList.ChildNodes[i];

				switch ( node.Name) 
				{
					case XMLDocumentFile.MAIN_NODE:
						this.Add ( new XMLDocumentFile(node));
						break;
				}
			}
		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(XMLDocumentAttachFiles.MAIN_NODE);

			for ( int i=0; i<this.Count;i++)
			{
				xmlNode.AddNode ( this[i].GetXMLNode() );
			}

			return xmlNode;
		}

		public XMLDocumentFile GetFileByName(string sFileName)
		{
			XMLDocumentFile file = null;
			for ( int i=0; i<this.List.Count;i++)
			{
				file = (XMLDocumentFile)this.List[i];
				if ( file.Name == sFileName) 
				{
					return file;
				}
			}

			return null;
		}

		public int AddDocumentFile (XMLDocumentFile docFile)
		{
			XMLDocumentFile file = null;
			for ( int i=0; i<this.List.Count;i++)
			{
				file = (XMLDocumentFile)this.List[i];
				if ( file.Name == docFile.Name) 
				{
					return 0;
				}
			}

			return this.List.Add (docFile);
		}
	}
}